<template>
  <div id="courseList">
    <div class="courseListCon">
      <div class="worksDetailNavInfo">
        <div><p>技能提升</p><span>&gt;</span><p>实战课堂</p><span>&gt;</span><p>课程列表</p></div>
      </div>
      <div class="teamworkContentMentoring">
        <div class="teamworkContentMentoringTitle">
          <label for="searchWorkroom">
            <input id="searchWorkroom" type="text" placeholder="请输入搜索内容" v-model="searchText" @keydown.enter="onSearchList()">
          </label>
          <div class="btnBox">
            <button class="btnDef" @click="onSearchList()">搜索</button>
          </div>
        </div>
        <!-- 低价好课 -->
        <div class="practicalClassroomContentCourse">
<!--          <h2>低价好课 <span @click="jumpTo('/courseList')">查看更多</span></h2>-->
          <ul>
            <li v-for="(item, index) in courseListData" :key="index" @click="jumpTo('/courseDetail?id=' + item.id)">
              <img :src="$globalImageUrl + item.courseImg" alt="">
              <div class="practicalClassroomContentCourseInfo">
                <h3 class="ellipse">{{item.courseName}}</h3>
                <p class="ellipse">{{item.introduce}}</p>
                <p class="ellipse">时长: {{item.courseDuration}}</p>
                <p style="padding-top: .1rem;"><i>￥{{item.presentPrice}}</i><b>￥{{item.originalPrice}}</b></p>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'courseList',
  data () {
    return {
      searchText: '',
      courseListData: [],
      sceneType: this.$route.query.sceneType
    }
  },
  created () {
    if (this.sceneType === 'newest') {
      this.fetchSkillNewCourse()
    } else if (this.sceneType === 'goodCourse') {
      this.fetchSkillGoodCourse()
    } else if (this.sceneType === 'lowPrice') {
      this.fetchSkillCheapCourse()
    }
  },
  methods: {
    onSearchList () {
      if (this.sceneType === 'newest') {
        this.fetchSkillNewCourse()
      } else if (this.sceneType === 'goodCourse') {
        this.fetchSkillGoodCourse()
      } else if (this.sceneType === 'lowPrice') {
        this.fetchSkillCheapCourse()
      }
    },
    // 最新课程
    fetchSkillNewCourse () {
      this.$api.getSkillNewCourse({
        categoryId: '',
        reclassifyId: '',
        searchText: this.searchText,
        pageNum: 1
      }).then(res => {
        if (res.code === 0) {
          this.courseListData = res.data
        }
      })
    },
    // 系列好课
    fetchSkillGoodCourse () {
      this.$api.getSkillGoodCourse({
        searchText: this.searchText,
        pageNum: 1
      }).then(res => {
        if (res.code === 0) {
          this.courseListData = res.data
        }
      })
    },
    // 低价好课
    fetchSkillCheapCourse () {
      this.$api.getSkillCheapCourse({
        searchText: this.searchText,
        pageNum: 1
      }).then(res => {
        if (res.code === 0) {
          this.courseListData = res.data
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
#courseList{
  .courseListCon{
    width: 1200px;
    margin: auto;
    padding: .2rem 0;
    .teamworkContentMentoring {
      padding-bottom: .4rem;

      .teamworkContentMentoringTitle {
        font-size: 0;
        padding-bottom: .3rem;

        label {
          width: 80%;
          display: inline-block;
          line-height: .4rem;
          background-color: #fff;
          padding-left: .15rem;
          border-radius: .05rem;
          vertical-align: top;
          border: 1px solid rgba(0, 0, 0, 0);

          input {
            font-size: .16rem;
            font-weight: 500;
            color: #333;
            line-height: .4rem;
            vertical-align: top;
          }
        }

        .btnBox {
          width: calc(100% - 80%);
          display: inline-block;
          vertical-align: top;
          padding-left: .2rem;
        }
      }
      .practicalClassroomContentCourse{
        background-color: #fff;
        padding: .2rem;
        margin-bottom: .2rem;
        h2{
          font-weight: 500;
          color: #333;
          font-size: .22rem;
          height: .4rem;
          line-height: .4rem;
          margin-bottom: .2rem;
          span{
            font-weight: 500;
            color: #333;
            font-size: .16rem;
            line-height: .6rem;
            height: .5rem;
            float: right;
          }
        }
        ul{
          li:nth-child(5n){
            margin-right: 0;
          }
          li{
            display: inline-block;
            margin-right: .125rem;
            margin-bottom: .125rem;
            box-shadow: 0 0 10px #eee;
            img{
              display: inline-block;
              width: 2.22rem;
              height: 1.5rem;
            }
            .practicalClassroomContentCourseInfo{
              padding: .1rem;
            }
            h3{
              font-weight: 500;
              color: #333;
              font-size: .16rem;
              line-height: .24rem;
            }
            p{
              font-weight: 500;
              color: #666;
              font-size: .14rem;
              line-height: .22rem;
              i{
                font-weight: 500;
                color: red;
                font-size: .14rem;
                line-height: .22rem;
                font-style: normal;
              }
              b{
                text-decoration: line-through;
                font-weight: 500;
                color: #999;
                font-size: .14rem;
                line-height: .22rem;
                padding-left: .05rem;
              }
            }
          }
        }
      }
    }
  }
}
</style>
